package com.CST.controller.cb;

import com.CST.common.api.ResultObject;
import com.CST.entity.cb.EtlAccount;
import com.CST.service.cb.IEtlAccountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@RestController
@RequestMapping("/etlAccount")
@Api(tags = "成本-薪酬/收入用友系统")
public class EtlAccountController {
    
    @Autowired
    private IEtlAccountService etlAccountService;
    
    @PostMapping("/getEtlAccountSource")
    @ApiOperation("条件查询")
    public ResultObject getEtlAccountSource(@RequestBody EtlAccount etlAccount){
        return etlAccountService.getEtlAccountSource(etlAccount);
    }
    
    @PostMapping("/getEtlAccountOrgationSource")
    @ApiOperation("关联查询")
    public ResultObject getEtlAccountOrgationSource(@RequestBody EtlAccount etlAccount){
        if (etlAccount.getSysid() == null || etlAccount.getSysid().isEmpty()) {
            return ResultObject.errorReturn("SysID不能为空");
        }
        if(etlAccount.getSysid().toLowerCase().equals("cost"))
        {
            etlAccount.setEdParentCode("RD_CostUFIDARelation");
        }
        else
        {
            etlAccount.setEdParentCode("RD_IncomeUFIDARelation");
        }
        return etlAccountService.getEtlAccountOrgationSource(etlAccount);
    }


    @PostMapping("/downLoadCostOfUf")
    @ApiOperation("成本-用友系统导出")
    public void downLoadCostOfUf(HttpServletResponse response, @RequestBody EtlAccount dto) throws Exception {
        etlAccountService.exportExcel(response,dto);
    }


    /**
     * @author xnd
     * @since 2021-10-28
     * 床位申请打印下载
     */
    @ApiOperation("成本-用友系统excle下载")
    @PostMapping("/getCostOfUfDownLoadExcel")
    public void getCostOfUfDownLoadExcel(@RequestBody EtlAccount requestInfo) throws IOException {
        etlAccountService.getCostOfUfDownLoadExcel(requestInfo);
    }
    
}
